package ${packageName};


import ${basePackage}.entity.${className};
import java.util.*;

import java.io.Serializable;

public class ${className}Service{

	public List<${className}> query(${className} param, KdConf dbConfig) throws Exception{
		StringBuilder sql = StringBuilder();
		sql.append(" SELECT");
		<#list attrs as attr>
		sql.append(" t.${attr.columnName}      as ${attr.camelName}")<#if attr_has_next>.append(",")</#if>;
		</#list>
		sql.append("   FROM ${tableName} t");
		sql.append("  WHERE 1 > 0 ");
		List<Object> paraList = new ArrayList();
		<#list attrs as attr>
		<#if attr.typeName?contains("String")>
		if(param.get${attr.pascalName}() != null && param.get${attr.pascalName}().length() > 0){
			sql.append("and ${attr.columnName} = ? ");
			paraList.add(param.get${attr.pascalName}());
		}
		<#else>
		if(param.get${attr.pascalName}() != null){
			sql.append("and ${attr.columnName} = ? ");
			paraList.add(param.get${attr.pascalName}());
		}
		</#if>

		</#list>
		List<${className}> dataList = KdDao.list(sql.toString(),paraList,${className}.class,dbConfig)
		return dataList;
	}

	public void update(${className} param, KdConf dbConfig) throws Exception{
		StringBuilder sql = StringBuilder(" UPDATE ${tableName} SET ");
		List<Object> paraList = new ArrayList();
		<#list attrs as attr>
		//${attr.label}
		sql.append("${attr.columnName}=?")<#if attr_has_next>.append(",")</#if>;
		paraList.add(param.get${attr.pascalName}());
		</#list>
		KdDao.run(sql.toString(),paraList,dbConfig)
	}

	public void delete(${className} param, KdConf dbConfig) throws Exception{
		String sql = " DELETE INTO ${tableName}  WHERE id ='"+param.getId()+"' ";
		KdDao.run(sql.toString(),dbConfig)
	}
}